/**
 * 
 */
package org.seginfo.httpfuzzer.header.impl;

import java.util.Random;
import org.seginfo.httpfuzzer.header.AttackStrategy;
import org.seginfo.httpfuzzer.header.HeaderPropertyImpl;

/**
 * @author Administrador
 *
 */
public class Referer extends HeaderPropertyImpl {
	
	private static final String NAME = "Referer";
	private static final String VALID = "http://www.google.com/";
	//private static final String WILDCARD = "*/*";
	private static final int BAD_STRING_MIN_LENGTH = 128;
	private static final int BAD_STRING_LENGTH = 256*16;

	private Random r;
	/**
	 * @param attackStrategy
	 */
	public Referer(AttackStrategy attackStrategy) {
		super(attackStrategy);
		r = new Random(9);
		this.value = this.generateValue();
	}

	/**
	 * @see org.seginfo.httpfuzzer.header.HeaderPropertyImpl#getName()
	 */
	public String getName() {
		return NAME;
	}

	/**
	 * @return
	 */
	private String generateValue() {
		
		String rv;

		double p = r.nextDouble();

		if (p < 0.002) {
			rv = VALID;
		} else if (p < 0.4) {
			rv = "http://"+attackStrategy.getStringAttack(BAD_STRING_MIN_LENGTH, BAD_STRING_LENGTH)+"/";
		} else if (p < 0.6) {
			rv = attackStrategy.getStringAttack(BAD_STRING_MIN_LENGTH, BAD_STRING_LENGTH)+"://"+attackStrategy.getStringAttack(BAD_STRING_MIN_LENGTH, BAD_STRING_LENGTH)+"/";
		} else if (p < 0.8) {
			rv = "/"+attackStrategy.getStringAttack(BAD_STRING_MIN_LENGTH, BAD_STRING_LENGTH)+"/";
		} else {
			rv = attackStrategy.getStringAttack(BAD_STRING_MIN_LENGTH, BAD_STRING_LENGTH);
		}

		return rv;
	}
}
